﻿namespace Blaze.Editor
{
    using UnityEditor;

    /// <summary>
    /// 将偏好设置限制在工程范围的<see cref="EditorPrefs"/>。
    /// </summary>
    public static class ProjectEditorPrefs
    {
        public static bool GetBool(string key, bool defaultValue = false)
        {
            key = makeKey(key);
            return EditorPrefs.GetBool(key, defaultValue);
        }

        public static float GetFloat(string key, float defaultValue = 0f)
        {
            return EditorPrefs.GetFloat(key, defaultValue);
        }

        public static int GetInt(string key, int defaultValue = 0)
        {
            key = makeKey(key);
            return EditorPrefs.GetInt(key, defaultValue);
        }

        public static string GetString(string key, string defaultValue = null)
        {
            key = makeKey(key);
            return EditorPrefs.GetString(key, defaultValue);
        }

        public static bool HasKey(string key)
        {
            key = makeKey(key);
            return EditorPrefs.HasKey(key);
        }

        public static void SetBool(string key, bool value)
        {
            key = makeKey(key);
            EditorPrefs.SetBool(key, value);
        }

        public static void SetFloat(string key, float value)
        {
            key = makeKey(key);
            EditorPrefs.SetFloat(key, value);
        }

        public static void SetInt(string key, int value)
        {
            key = makeKey(key);
            EditorPrefs.SetInt(key, value);
        }

        public static void SetString(string key, string value)
        {
            key = makeKey(key);
            EditorPrefs.SetString(key, value);
        }

        private static string makeKey(string key)
        {
            return $"{BlazeEditorConfig.Instance.ProjectName}.{key}";
        }
    }
}